package byf.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcSelect {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        //jdbc连接协议，主机名或ip
        String url="jdbc:mysql://localhost:33306/test?useSSL=false";
        //MySQL连接账号
        String username="root";
        //连接密码
        String password="root";
        Connection connection = DriverManager.getConnection(url, username, password);

        Statement statement = connection.createStatement();
        String sql = "SELECT id,`username`FROM user order by id";
        ResultSet set = statement.executeQuery(sql);

        while(set.next()){
            long id = set.getLong(1);
            String name = set.getString(2);
            System.out.printf(id+"  "+name+'\n');
        }

    }
}
